package com.ysd.ziyuanshiyongtongji.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.ysd.ziyuanshiyongtongji.dto.ReadRoomDTO;
import com.ysd.ziyuanshiyongtongji.model.ReadRoom;
import com.ysd.ziyuanshiyongtongji.service.IReadRoomService;

import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;

/**
 * ReadRoomController
 */
@ApiOperation("资源列表页")
@RestController
@RequestMapping(path = "/readroom",method=RequestMethod.POST)
public class ReadRoomController {
@Resource
private IReadRoomService readRoomService;
@ApiOperation(value = "分页查询",notes = "分页查询")
@PostMapping("/findPage")
public Map<String,Object> findPage(@RequestBody ReadRoomDTO dto){
    Page<ReadRoom> page=readRoomService.findPage(dto);
    Map<String, Object> map=new HashMap<String, Object>();
        map.put("code",0);
        map.put("data", page.getContent());
	    	return map;
} 
@ApiOperation(value = "保存资源信息",notes = "添加或修改")
@PostMapping("/add")
public ReadRoom saveMember(@RequestBody ReadRoom r){
    return readRoomService.saveReadRoom(r);
}
@ApiOperation(value = "删除",notes = "删除")
@DeleteMapping(value = "/delete")
public void deletebatch(@RequestBody String id){
   System.out.println(id);
   String[] str=id.split(",");
   System.out.println(str.toString());
   List<Integer> list=new ArrayList<>();
   for(String l : str){
   Integer i=Integer.valueOf(l);
    list.add(i);
   }
   readRoomService.deletebatch(list);
}  
@ApiOperation(value = "删除添加",notes = "删除资源信息")
@DeleteMapping("/{id}")
public void del(@PathVariable Integer id){
    readRoomService.del(id);
}
}